package day4.Weeken1;

import java.util.Scanner;

import org.junit.Test;

public class Text {
	public static void main(String[] args){
		for(int i=0;i<3;i++){
			switch(i){
			case 1:
				System.out.println("a");
				break;
			case 0:
				System.out.println("b");
				break;
			default:
				System.out.println("c");
			case 2:
				System.out.println("d");
			}
		}
	}
	
//	* * * * *
//	* * * *
//	* * *
//	* *
//	*
	@Test
	public void test1() {
		for (int i = 1; i <= 5; i++) {
			for (int j = 1; j <= 6 - i; j++) {
				System.out.print("*");
			}
			System.out.println();
		}
	}
	
//	编写一个方法求s=a+aa+aaa+a...a，其中a是一个数，比如a=2；那么求s=2+22+222+2222...的值。
//	该方法需要两个参数，第一个参数控制a，第二个参数控制有多少个数。
	
	@Test
	public void test2() {
		Scanner scanner = new Scanner(System.in);
		int sum = 0;
		System.out.println("请输入一个0-9的数：");
		int a = scanner.nextInt();
		while (true) {
			if (a > 0 && a < 10) {
				break;
			}
			System.out.println("输入的数非法，请重新输入：");
			a = scanner.nextInt();
		}
		System.out.println("请输入要求和的次数：");
		int count = scanner.nextInt();
		int[] array = new int[count];
		array[0] = 1 * a;
		for (int i = 1; i < array.length; i++) {
			int num = 10;
			int power = power(num, i);
			array[i] = array[i - 1] + power * a;
		}
		for (int i = 0; i < array.length; i++) {
			sum = sum + array[i];
		}
		System.out.println("此数列的和为：" + sum);
	}
	
	public int power(int num, int i) {
		int pow = 10;
		for (int j = 1; j < i; j++) {
			pow = pow * 10;
		}
		return pow;
	}
	
//	给出一组学生的成绩int[] score={80,45,60,100,89,92,93,...}请求出这组成绩中，100分，90-99，80-89的学生人数。
	
	@Test
	public void test3() {
		Scanner scanner = new Scanner(System.in);
		System.out.println("请输入学生人数：");
		double[] score = new double[scanner.nextInt()];
		System.out.println("请输入学生成绩：");
		for (int i = 0; i < score.length; i++) {
			while(true) {
				double temporary = scanner.nextDouble(); // 存放一个临时的分数，用于判断是否非法
				if(temporary >= 0 && temporary <= 100) {
					score[i] = temporary;
					break;
				}
				System.out.println("成绩非法，请重新输入上一个成绩：");
			}
		}
		int count1 = 0; 
		int count2 = 0; 
		int count3 = 0; 
		for (int i = 0; i < score.length; i++) {
//			System.out.print(score[i] + " ");
			if (score[i] == 100) {
				count1++;
			} else if (score[i] >= 90 && score[i] < 100) {
				count2++;
			} else if (score[i] >= 80 && score[i] < 90) {
				count3++;
			} 
		}
		System.out.println("100分的人数：" + count1);
		System.out.println("90-99分的人数：" + count2);
		System.out.println("80-89分的人数：" + count3);
	}
	
	@Test
	public void test4() {
		Scanner scanner = new Scanner(System.in);
		System.out.println("请输入一个数：");
		int num = scanner.nextInt();
		System.out.println("请输入要求和的次数：");
		int count = scanner.nextInt();
		if (count == 0) {
			System.out.println("求和次数为0，和为0");
			return;
		}
		int result = show(num, count);
	}

	private int show(int num, int count) {
		int sum = 0;
		String temp = "";
		String exp = "";
		for (int i = 1; i <= count; i++) {
			temp += num;
			sum += Integer.parseInt(temp);
			exp += temp;
			exp += "+";
		}
		exp = exp.substring(0, exp.length() - 1);
		System.out.println(exp + "=" + sum);
		return sum;
	}
}
